package org.kl.bf.utils;

import java.security.MessageDigest;

/**
 * @Author hqm
 * @CreateTime 2013-6-24 上午11:18:03
 */
public class MD5Util {
	public static byte[] MD5Encode(byte[] origin) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return md.digest(origin);
		} catch (Exception ex) {
		}
		return null;
	}

	public static byte[] doubleMD5Encode(byte[] origin) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return md.digest(md.digest(origin));
		} catch (Exception ex) {
		}
		return null;
	}

	public static String mD5Encode(String origin) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return CommonUtil.byteArrayToHexString(md.digest(origin.getBytes()));
		} catch (Exception ex) {
		}
		return null;
	}

	public static String mD5Encode(String origin, String charset) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return CommonUtil.byteArrayToHexString(md.digest(origin.getBytes(charset)));
		} catch (Exception ex) {
		}
		return null;
	}

	public static void main(String[] args) {
		byte[] origin = "00010     002008-06-30".getBytes();

		System.out.println(CommonUtil.byteArrayToHexString(MD5Encode(origin)));
	}
}
